package com.ruoyi.system.service.impl.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CoTestMenu;
import com.ruoyi.system.service.ICoTestMenuService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 菜单管理Controller
 * 
 * @author 冬木逢春
 * @date 2022-06-19
 */
@Controller
@RequestMapping("/system/MyMenu")
public class CoTestMenuController extends BaseController
{
    private String prefix = "system/MyMenu";

    @Autowired
    private ICoTestMenuService coTestMenuService;

    @RequiresPermissions("system:MyMenu:view")
    @GetMapping()
    public String MyMenu()
    {
        return prefix + "/MyMenu";
    }

    /**
     * 查询菜单管理列表
     */
    @RequiresPermissions("system:MyMenu:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CoTestMenu coTestMenu)
    {
        startPage();
        List<CoTestMenu> list = coTestMenuService.selectCoTestMenuList(coTestMenu);
        return getDataTable(list);
    }

    /**
     * 导出菜单管理列表
     */
    @RequiresPermissions("system:MyMenu:export")
    @Log(title = "菜单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CoTestMenu coTestMenu)
    {
        List<CoTestMenu> list = coTestMenuService.selectCoTestMenuList(coTestMenu);
        ExcelUtil<CoTestMenu> util = new ExcelUtil<CoTestMenu>(CoTestMenu.class);
        return util.exportExcel(list, "菜单管理数据");
    }

    /**
     * 新增菜单管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存菜单管理
     */
    @RequiresPermissions("system:MyMenu:add")
    @Log(title = "菜单管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CoTestMenu coTestMenu)
    {
        return toAjax(coTestMenuService.insertCoTestMenu(coTestMenu));
    }

    /**
     * 修改菜单管理
     */
    @RequiresPermissions("system:MyMenu:edit")
    @GetMapping("/edit/{menuId}")
    public String edit(@PathVariable("menuId") Long menuId, ModelMap mmap)
    {
        CoTestMenu coTestMenu = coTestMenuService.selectCoTestMenuByMenuId(menuId);
        mmap.put("coTestMenu", coTestMenu);
        return prefix + "/edit";
    }

    /**
     * 修改保存菜单管理
     */
    @RequiresPermissions("system:MyMenu:edit")
    @Log(title = "菜单管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CoTestMenu coTestMenu)
    {
        return toAjax(coTestMenuService.updateCoTestMenu(coTestMenu));
    }

    /**
     * 删除菜单管理
     */
    @RequiresPermissions("system:MyMenu:remove")
    @Log(title = "菜单管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(coTestMenuService.deleteCoTestMenuByMenuIds(ids));
    }
}
